
package ${config.basePackage}.mapper;

import ${config.basePackage}.model.entity.${table.className}Entity;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class ${table.className}MapperTest {

    @Mock
    private ${table.className}Mapper ${table.className?uncap_first}Mapper;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testList() {
        // 准备测试数据
        Map<String, Object> params = new HashMap<>();
        List<${table.className}Entity> expectedList = new ArrayList<>();

        // 设置mock行为
        when(${table.className?uncap_first}Mapper.list(params)).thenReturn(expectedList);

        // 执行测试
        List<${table.className}Entity> result = ${table.className?uncap_first}Mapper.list(params);

        // 验证结果
        assertNotNull(result);
        assertSame(expectedList, result);
        verify(${table.className?uncap_first}Mapper, times(1)).list(params);
    }

    @Test
    public void testSave() {
        // 准备测试数据
        ${table.className}Entity entity = new ${table.className}Entity();

        // 设置mock行为
        when(${table.className?uncap_first}Mapper.save(entity)).thenReturn(1);

        // 执行测试
        int affectedRows = ${table.className?uncap_first}Mapper.save(entity);

        // 验证结果
        assertEquals(1, affectedRows);
        verify(${table.className?uncap_first}Mapper, times(1)).save(entity);
    }

    @Test
    public void testUpdate() {
        // 准备测试数据
        ${table.className}Entity entity = new ${table.className}Entity();

        // 设置mock行为
        when(${table.className?uncap_first}Mapper.update(entity)).thenReturn(1);

        // 执行测试
        int affectedRows = ${table.className?uncap_first}Mapper.update(entity);

        // 验证结果
        assertEquals(1, affectedRows);
        verify(${table.className?uncap_first}Mapper, times(1)).update(entity);
    }
}
